/*
 * @Author: your name
 * @Date: 2021-09-15 10:43:13
 * @LastEditTime: 2022-09-23 16:19:07
 * @LastEditors: zshawk1982
 * @Description: 血糖模型定义
 * @FilePath: \media_system\database\models\article.js
 */
var moment = require("moment");
module.exports = (sequelize, DataTypes) => {
  const Bloodglucose = sequelize.define(
    "bloodglucose",
    {
      bloodglucoseId: {
        type: DataTypes.UUID,
        primaryKey: true,
        defaultValue: DataTypes.UUIDV4,
        comment: "血糖ID",
      },
      bloodglucoseValue: {
        type: DataTypes.DOUBLE,
        comment: "血糖值",
      },
      recordTime:{
        type: DataTypes.DATE,
        get() {
          const recordTime = this.getDataValue("recordTime");
          return moment(recordTime).format("YYYY-MM-DD HH:mm:ss");
        },
        set(recordTime) {
          return this.setDataValue("recordTime", recordTime);
        },
        comment: '记录时间'
      },
      dietStatus: {
        //0早餐前 1 早餐后 2午餐前 3午餐后 4晚餐前 5晚餐后 6睡前 7凌晨 8随机
        type: DataTypes.INTEGER,
        comment: "血糖检测状态",
      },
      createdAt: {
        type: DataTypes.DATE,
        get() {
          const createdAt = this.getDataValue("createdAt");
          // createAt is an instance of date, you could operate it with moment library
          // to get ur format
          return moment(createdAt).format("YYYY-MM-DD HH:mm:ss");
        },
        set(createdAt) {
          return this.setDataValue("createdAt", createdAt);
        },
      },
      updatedAt: {
        type: DataTypes.DATE,
        get() {
          const updatedAt = this.getDataValue('updatedAt')
          // createAt is an instance of date, you could operate it with moment library
          // to get ur format
         return moment(updatedAt).format('YYYY-MM-DD HH:mm:ss');
        },
        set(updatedAt) {
          return this.setDataValue('updatedAt',updatedAt)
        }
      }
    },
    {
      tableName: "bloodglucoses",
      timestamps: true,
    }
  );

  return Bloodglucose;
};
